<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class BuffersController extends AppController {

    public $helpers = array('Html', 'Form');

   function setting(){

   	 $hours = ClassRegistry::init('Hour')->find('all', array(
            'joins' =>
            array(
                array(
                    'table' => 'buffers',
                    'alias' => 'Buffers',
                    'type' => 'LEFT',
                    'conditions' => array(
                        'id=buffer_id ',
                ))),
            'conditions' => array('Buffers.account_id' => $this->Auth->User('current_account'))
                ));

   	 $this->set('counter',count($hours));
   	 $this->set('hours',$hours);
   
   	 
   	

   }

   function edit($hour_id =null){

   // print_r($this->request->data);
    $string= $this->request->data['Buffer']['0']['hour'].":".$this->request->data['Buffer']['1']['min']." ".$this->request->data['Buffer']['2']['meridian'];
    ClassRegistry::init('Hour')->id = $hour_id;
    //print_r(ClassRegistry::init('Hour')->id);
    $data = array('hour_id' => $hour_id, 'hour' => $string);

        if (ClassRegistry::init('Hour')->saveField('hour' , $string)) {
            $this->Session->setFlash('Your post has been updated.');
            $this->redirect(array('action' => 'setting'));
        } else {
            $this->Session->setFlash('Unable to update your post.');
        }
    


   }


   function delete($hour,$buffer_id){

    print_r($hour);
   print_r($buffer_id);

    $id = ClassRegistry::init('Hour')->find('first',array('hour'=>$hour,'buffer_id'=>$buffer_id));

if ($this->request->is('get')) {
        throw new MethodNotAllowedException();
    }
    if (ClassRegistry::init('Hour')->deleteAll(array('hour'=>$hour,'buffer_id'=>$buffer_id),false)) {

        $this->redirect(array('action' => 'setting'));
    }


   }

   function index(){}

}

?>
